/*
 * @(#)CustomerList.java
 *
 */

package customerList;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Timestamp;

/**
 * description 自定义列表页
 * @author  huangyixiang
 * @version 2012-6-29
 */
public class CustomerList {
	
	static String driver = "com.mysql.jdbc.Driver";
	static String url = "jdbc:mysql://10.1.2.7:33306/newshop_test?useUnicode=true&amp;characterEncoding=utf-8&amp;zeroDateTimeBehavior=convertToNull&amp;useServerPrepStmts=false";
	static String user = "winxuan_test";
	static String password = "poiuyhbvgt";
	
	public static void main(String[] args) throws IOException, ClassNotFoundException, SQLException {
		
		readFile();
	}
	
	public static void readFile() throws IOException, ClassNotFoundException, SQLException{
		String fileName = "C:/list.txt";
		Timestamp createTime = new Timestamp(System.currentTimeMillis());
		String flag = "国家公务员";
		
		FileReader fr = new FileReader(fileName);
		BufferedReader br = new BufferedReader(fr);
		
		String myreadline;
		while (br.ready()) {
			myreadline = br.readLine();
			if(myreadline != null && !myreadline.trim().equals("")){
				Long productSale = Long.parseLong(myreadline);
				System.out.println(productSale);
				insert(productSale, flag, createTime);
			}
		}
		
		br.close();
		fr.close();
	}
	
	public static void insert(Long procudtSale,String flag,Timestamp time) throws ClassNotFoundException, SQLException{
		Class.forName(driver);
		Connection conn = DriverManager.getConnection(url, user, password);
		String sql = "insert into search_list_customer (productsale,flag,createtime) VALUES (? , ? , ?)" ;
		
		
		PreparedStatement statement = conn.prepareStatement(sql);
		statement.setLong(1, procudtSale);
		statement.setString(2, flag);
		statement.setTimestamp(3, time);
		statement.executeUpdate();

		if(conn!=null)conn.close();
	}

}
